var http = require('http');
var url = require('url');
var util = require('util');
var sha1 = require('sha1');

module.exports = function(req, res, query) {
	var signature = query.signature;
	if(!signature){
		console.log("再见了，亲")
		res.writeHeader(200, {
			"Content-type": "text/html;charset=utf8"
		})
		res.end('<h1  style="color: #ff4e2f;margin:auto;">再见了，亲</h1>')
	}
	
	var signature = query.signature;
	var timestamp = query.timestamp;
	var echostr = query.echostr;
	var nonce = query.nonce;
	var token = "wwjTest";

	var str = [token, timestamp, nonce].sort().join('');
	let sha = sha1(str);
	if (sha == signature) {
		res.end(echostr);
	} else {
		res.end();
	}
	console.log(sha)
	console.log(signature + "--" + timestamp + "--" + nonce)
}
